package com.weipai.education.dao.impl;

import com.weipai.education.dao.ProductDao;
import com.weipai.education.mapper.ProductDescMapper;
import com.weipai.education.mapper.ProductGoodsMapper;
import com.weipai.education.mapper.ProductMapper;
import com.weipai.education.mapper.ProductPriceMapper;
import com.weipai.education.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @Author: 曹朋飞
 * @Date: 2018/12/11 13:25
 */
@Repository
public class ProductDaoImpl implements ProductDao {
    
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private ProductDescMapper productDescMapper;
    @Autowired
    private ProductPriceMapper productPriceMapper;
    @Autowired
    private ProductGoodsMapper productGoodsMapper;

    @Override
    public List<Map<String, Object>> list(Integer start, Integer size, Integer key, String productCateId) {
        return productMapper.list(start, size, key, productCateId);
    }

    @Override
    public Product listNumber(String name) {
        return productMapper.listNumber(name);
    }

    @Override
    public Integer listAmount(Integer key, String productCateId) {
        return productMapper.listAmount(key, productCateId);
    }

    @Override
    public ProductDesc selectProductDescByProductId(Integer productId) {
        return productDescMapper.selectProductDescByProductId(productId);
    }

    @Override
    public int updateProduct(Product product) {
        return productMapper.updateByPrimaryKeySelective(product);
    }

    @Override
    public int updateProductDesc(ProductDesc productDesc) {
        return productDescMapper.updateByPrimaryKeySelective(productDesc);
    }

    @Override
    public int insertProduct(Product product) {
        return productMapper.insert(product);
    }

    @Override
    public int insertProductDesc(ProductDesc productDesc) {
        return productDescMapper.insert(productDesc);
    }

    @Override
    public Product selectByPrimaryKey(String id) {
        return productMapper.selectByPrimaryKey(Integer.parseInt(id));
    }

    @Override
    public Map<String, Object> getProductInfo(String productId) {
        return productMapper.getProductInfo(productId);
    }

    @Override
    public Map<String, Object> getProductPriceByUserId(String productId, String userId) {
        return productPriceMapper.getProductPriceByUserId(productId, userId);
    }

    @Override
    public void insertProductPrice(List<ProductPrice> productPrice) {
        for(ProductPrice price : productPrice){
            productPriceMapper.insert(price);
        }
    }

    @Override
    public void updateProductPrice(List<ProductPrice> productPrice) {
        for(ProductPrice price : productPrice){
            productPriceMapper.updateByPrimaryKeySelective(price);
        }
    }

    @Override
    public List<Map<String, Object>> getProductPrice(String productId) {
        return productPriceMapper.getProductPrice(productId);
    }

    @Override
    public int insertProductGoods(ProductGoods productGoods) {
        return productGoodsMapper.insert(productGoods);
    }

    @Override
    public int insertNumber(Integer productNumber) {
        return productMapper.insertNumber(productNumber);
    }



    @Override
    public List<Map<String, Object>> getAllGoodsBar(Integer productId, String type) {
        return productGoodsMapper.getAllGoodsBar(productId, type);
    }

    @Override
    public List<Map<String, Object>> getProductPriceByProductCateIdAndUserCateId(Integer productCateId, Integer userCateId) {
        return productPriceMapper.getProductPriceByProductCateIdAndUserCateId(productCateId, userCateId);
    }

    @Override
    public int getGoodsBarCountByProductId(Object productId) {
        return productGoodsMapper.getGoodsBarCountByProductId(productId);
    }

    @Override
    public List<Map<String, Object>> getProductBySpuNumber(String spuNumber) {
        return productMapper.getProductBySpuNumber(spuNumber);
    }

    @Override
    public int updateProductGoods(String goodsBarCode, int isUse, String isPrice, String isDamage) {
        return productGoodsMapper.updateProductGoods(goodsBarCode, isUse, isPrice, isDamage);
    }

    @Override
    public PurchaseDetail getProductById(String productName) {
        return productMapper.getProductById(productName);
    }


}
